/**
 * 分页相关mixin
 * @param {string} [callbackKey='getTableData'] 默认回调函数的name
 * @param {number} [defaultSize=10] 默认一页展示的个数
 */
export function pagingMixin(callbackKey = 'getTableData', defaultSize = 10) {
  return {
    data() {
      return {
        paging: {
          total: 0,
          size: defaultSize,
          page: 1,
        },
      };
    },
    methods: {
      resetPage() {
        this.paging.page = 1;
      },
      handleCurrentChange(currentPage) {
        this.paging.page = currentPage;
        this[callbackKey]();
      },
      handleSizeChange(pageSize) {
        this.paging.page = 1;
        this.paging.size = pageSize;
        this[callbackKey]();
      },
    },
  };
}
